home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / game / board / Chaos_src.lha / chaos / src / MainAmi.c < prev    next >
C/C++ Source or Header  |  1995-06-05  |  41KB  |  1,155 lines

  1. /*  Chaos:                  The Chess HAppening Organisation System     V5.3
  2.     Copyright (C)   1993    Jochen Wiedmann
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19.     $RCSfile: MainAmi.c,v $
  20.     $Revision: 3.4 $
  21.     $Date: 1994/11/19 19:32:01 $
  22.  
  23.     This file contains the system dependent functions to initialize the
  24.     main window and other global stuff. Highly system dependent.
  25.  
  26.     Computer:   Amiga 1200                  Compiler:   Dice 2.07.54 (3.0)
  27.  
  28.     Author:     Jochen Wiedmann
  29.                 Am Eisteich 9
  30.           72555 Metzingen
  31.                 Tel. 07123 / 14881
  32.                 Internet: jochen.wiedmann@zdv.uni-tuebingen.de
  33. */
  34.  
  35.  
  36. #ifndef CHAOS_H
  37. #include "chaos.h"
  38. #endif
  39.  
  40. #ifdef AMIGA
  41. #include <workbench/startup.h>
  42. #include <libraries/gadtools.h>
  43. #include <dos/dostags.h>
  44. #include <proto/icon.h>
  45. #endif  /*  AMIGA   */
  46.  
  47.  
  48.  
  49.  
  50.  
  51. /*
  52.     CloseLibs() closes the libraries.
  53. */
  54. #ifdef AMIGA
  55. struct Library *MUIMasterBase   = NULL;
  56. struct Library *IFFParseBase    = NULL;
  57. #endif  /*  AMIGA   */
  58.  
  59. void CloseLibs(void)
  60.  
  61. #ifdef AMIGA
  62. {
  63.   if (MUIMasterBase != NULL)
  64.   { CloseLibrary(MUIMasterBase);
  65.   }
  66.   if (IFFParseBase != NULL)
  67.   { CloseLibrary(IFFParseBase);
  68.   }
  69. }
  70. #endif  /*  AMIGA   */
  71.  
  72.  
  73. /*
  74.     DoStartup() processes the arguments (either from workbench or from
  75.     CLI). Note, that this is called before InitMain(). ShowError() probably
  76.     doesn't do its job, if it's called.
  77. */
  78. #ifdef AMIGA
  79. int MakeIcons;
  80. int NoWindow;
  81. char IconName[TRNFILENAME_LEN+1] = "s/Chaos_Project";
  82. char MenuName[TRNFILENAME_LEN+1] = "s/Chaos_Menu";
  83. char ProgName[TRNFILENAME_LEN+1];
  84. Object *MainMenu;
  85. #endif  /*  AMIGA   */
  86.  
  87. void DoStartup(int argc, char *argv[])
  88.  
  89. #ifdef AMIGA
  90. { struct
  91.   { char *name;
  92.     long makeicons;
  93.     char *deficon;
  94.     char *menufile;
  95.     char *language;
  96.     long nowindow;
  97.     long *winnerpoints;
  98.     long *drawpoints;
  99.   } args;
  100.   void *key = NULL;
  101.  
  102.   args.name = NULL;
  103.   args.makeicons = (argc == 0);
  104.   args.deficon = NULL;
  105.   args.menufile = NULL;
  106.   args.language = NULL;
  107.   args.nowindow = FALSE;
  108.   args.winnerpoints = NULL;
  109.   args.drawpoints = NULL;
  110.  
  111.   if (argc == 0)  /*  Workbench-Programm  */
  112.   { struct WBStartup *WBenchMsg = (struct WBStartup *) argv;
  113.     struct WBArg *wbarg;
  114.     struct DiskObject *dobj;
  115.     char **toolarray;
  116.     char *ptr;
  117.     BPTR olddir;
  118.     int i;
  119.  
  120.     AllowErrorMessage = FALSE;
  121.     for (i = 0,  wbarg = WBenchMsg->sm_ArgList;
  122.          i < ((2 < WBenchMsg->sm_NumArgs) ? 2 : WBenchMsg->sm_NumArgs);
  123.          i++, wbarg++)
  124.     { olddir = -1;
  125.       if (wbarg->wa_Lock  &&  *wbarg->wa_Name != '\0')
  126.       { olddir = CurrentDir(wbarg->wa_Lock);
  127.       }
  128.       if (*wbarg->wa_Name != '\0'  &&
  129.           (dobj = GetDiskObject((STRPTR) wbarg->wa_Name))  !=  NULL)
  130.       { toolarray = (char **) dobj->do_ToolTypes;
  131.  
  132.         if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  133.                                                  (STRPTR) "NOICONS"))
  134.                  !=  NULL)
  135.         { args.makeicons = FALSE;
  136.         }
  137.         if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  138.                                                  (STRPTR) "DEFICON"))
  139.                  !=  NULL)
  140.         { args.deficon = GetStringMem(&key, ptr);
  141.           args.makeicons = TRUE;
  142.         }
  143.         if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  144.                                                  (STRPTR) "MENUFILE"))
  145.                  !=  NULL)
  146.         { args.deficon = GetStringMem(&key, ptr);
  147.           args.makeicons = TRUE;
  148.         }
  149.         if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  150.                                                  (STRPTR) "LANGUAGE"))
  151.                  != NULL)
  152.         { args.language = GetStringMem(&key, ptr);
  153.         }
  154.         if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  155.                                          (STRPTR) "WINNERPOINTS"))
  156.                  != NULL)
  157.         { DefaultWinnerPoints = atol(ptr);
  158.         }
  159.         if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  160.                                          (STRPTR) "DRAWPOINTS"))
  161.                  != NULL)
  162.         { DefaultDrawPoints = atol(ptr);
  163.         }
  164.  
  165.         FreeDiskObject(dobj);
  166.       }
  167.       if (i == 0)
  168.       { /*  Get program's pathname
  169.         */
  170.         if (!NameFromLock(wbarg->wa_Lock, (STRPTR) ProgName,
  171.                           sizeof(ProgName)-strlen(wbarg->wa_Name)-1))
  172.         { *ProgName = '\0';
  173.         }
  174.         AddPart((STRPTR) ProgName,
  175.                 (STRPTR) wbarg->wa_Name, sizeof(ProgName));
  176.       }
  177.       else
  178.       { /* Get filename to load
  179.         */
  180.         char filename[TRNFILENAME_LEN+1];
  181.  
  182.         if (NameFromLock(wbarg->wa_Lock, (STRPTR) filename,
  183.                          sizeof(filename)-strlen(wbarg->wa_Name)-1))
  184.         { AddPart((STRPTR) filename, (STRPTR) wbarg->wa_Name,
  185.                   sizeof(filename));
  186.           args.name = GetStringMem(&key, filename);
  187.         }
  188.       }
  189.       if (olddir != -1)
  190.       { CurrentDir(olddir);
  191.       }
  192.     }
  193.   }
  194.   else            /*  CLI program       */
  195.   { struct RDArgs *rdargs;
  196.  
  197.     if ((rdargs = ReadArgs((STRPTR)
  198.                             "FILE,MAKEICONS/S,DEFICON/K,MENUFILE/K,"
  199.                             "LANGUAGE/K,NOWINDOW/S,WINNERPOINTS/K/N,"
  200.                             "DRAWPOINTS/K/N",
  201.                            (LONG *) &args, NULL))
  202.                 ==  NULL)
  203.     { PrintFault(IoErr(), NULL);
  204.       exit(10);
  205.     }
  206.     if (args.name)
  207.     { args.name = GetStringMem(&key, args.name);
  208.     }
  209.     if (args.language)
  210.     { args.language = GetStringMem(&key, args.language);
  211.     }
  212.     if (args.deficon)
  213.     { args.deficon = GetStringMem(&key, args.deficon);
  214.     }
  215.     if (args.menufile)
  216.     { args.menufile = GetStringMem(&key, args.menufile);
  217.     }
  218.     if (args.winnerpoints)
  219.     { DefaultWinnerPoints = *args.winnerpoints;
  220.     }
  221.     if (args.drawpoints)
  222.     { DefaultDrawPoints = *args.drawpoints;
  223.     }
  224.     FreeArgs(rdargs);
  225.  
  226.     /*  Pfadnamen des Programms bestimmen.
  227.     */
  228.     if (!NameFromLock(((struct Process *) FindTask(NULL))->pr_HomeDir,
  229.                       (STRPTR) ProgName,
  230.                       sizeof(ProgName)-strlen(argv[0])-1))
  231.     { *ProgName = '\0';
  232.     }
  233.     AddPart((STRPTR) ProgName, (STRPTR) argv[0], sizeof(ProgName));
  234.   }
  235.  
  236.   MakeIcons = args.makeicons;
  237.   NoWindow = args.nowindow;
  238.   if (args.deficon != NULL)
  239.   { MakeIcons = TRUE;
  240.     strcpy(IconName, args.deficon);
  241.   }
  242.   if (args.menufile != NULL)
  243.   { strcpy(MenuName, args.menufile);
  244.   }
  245.  
  246.  
  247.  
  248.   InitChaosCatalog((STRPTR) args.language);
  249.   if (args.name != NULL)
  250.   { LoadTournament(args.name, NULL, NULL);
  251.   }
  252.   PutMemList(&key);
  253. }
  254. #endif  /*  AMIGA   */
  255.  
  256.  
  257.  
  258.  
  259. /*
  260.     This initializes the libraries.
  261. */
  262. void OpenLibs(void)
  263.  
  264. #ifdef AMIGA
  265. { /*  Not all of the above are really needed. Without iffparse.library
  266.       we read the preferences like we did in 1.3 and use the english
  267.       strings on 2.0. Without locale.library we use the english strings
  268.       on 2.1 and above.
  269.   */
  270.   if ((MUIMasterBase = OpenLibrary((STRPTR) "muimaster.library", 8))
  271.                      ==  NULL)
  272.   { ShowError("Cannot open 'mui.library' V8 or higher!");
  273.     exit(10);
  274.   }
  275.   IFFParseBase = OpenLibrary((STRPTR) "iffparse.library", 37);
  276. }
  277. #endif  /*  AMIGA   */
  278.  
  279.  
  280.  
  281. /*
  282.     The InitRandom() function initializes the random number generator.
  283. */
  284. void InitRandom(void)
  285.  
  286. #ifdef AMIGA
  287. { int i;
  288.   struct DateStamp ds;
  289.   extern ULONG RangeSeed;
  290.  
  291.   DateStamp(&ds);
  292.   RangeSeed = ds.ds_Days + ds.ds_Minute + ds.ds_Tick/2;
  293.   for (i = 0;  i < ds.ds_Minute;  i++)
  294.   { RangeRand(ds.ds_Tick);
  295.   }
  296. }
  297. #endif  /*  AMIGA   */
  298.  
  299.  
  300.  
  301. /*
  302.     TerminateWnd() closes the main window.
  303. */
  304. #ifdef AMIGA
  305. APTR App = NULL;                                /*  Application object      */
  306. struct DiskObject *AppDiskObject    = NULL;     /*  Icon in iconified state */
  307. #endif  /*  AMIGA   */
  308.  
  309. void TerminateMainWnd(void)
  310.  
  311. #ifdef AMIGA
  312. {
  313.   if (App)
  314.   { MUI_DisposeObject(App);
  315.     App = NULL;
  316.   }
  317.   if (AppDiskObject)
  318.   { FreeDiskObject(AppDiskObject);
  319.   }
  320. }
  321. #endif  /*  AMIGA   */
  322.  
  323.  
  324.  
  325.  
  326. /*
  327.     The InitMainWnd() function brings up the main window. The program is
  328.     terminated, if an error occurs.
  329. */
  330. #ifdef AMIGA
  331. APTR MainWnd;               /*  Main window                         */
  332. static APTR TrnFileGad;     /*  Tournament file name                */
  333. static APTR TrnNameGadOut;  /*  Tournament name (output)            */
  334. static APTR TrnModeGad;     /*  Tournament mode                     */
  335. static APTR NumPlayersGad;  /*  Number of players                   */
  336. static APTR NumRoundsGad;   /*  Number of rounds                    */
  337.  
  338.  
  339. #define ID_MenuAction                       1
  340. #define ID_Project_New                      1001
  341. #define ID_Project_Load                     1002
  342. #define ID_Project_Save                     1003
  343. #define ID_Project_SaveAs                   1004
  344. #define ID_Project_About                    1005
  345. #define ID_Project_Quit                     1006
  346. #define ID_Players_Add                      1007
  347. #define ID_Players_Import                   1008
  348. #define ID_Players_Modify                   1009
  349. #define ID_Players_Delete                   1010
  350. #define ID_Round_Pairings                   1011
  351. #define ID_Round_Pairings_SwissPairing      1012
  352. #define ID_Round_Pairings_RoundRobin        1013
  353. #define ID_Round_Pairings_RoundRobinShift   1014
  354. #define ID_Round_Results                    1015
  355. #define ID_Round_Results_Sub                1016
  356. #define ID_Output_PlayerList                1017
  357. #define ID_Output_PlayerList_Short          1018
  358. #define ID_Output_PlayerList_Long           1019
  359. #define ID_Output_Rankings                  1020
  360. #define ID_Output_Round                     1021
  361. #define ID_Output_Round_Sub                 1022
  362. #define ID_Output_Table                     1023
  363. #define ID_Output_Table_All                 1024
  364. #define ID_Output_Table_Seniors             1025
  365. #define ID_Output_Table_Juniors             1026
  366. #define ID_Output_Table_Women               1027
  367. #define ID_Output_Table_JuniorsA            1028
  368. #define ID_Output_Table_JuniorsB            1029
  369. #define ID_Output_Table_JuniorsC            1030
  370. #define ID_Output_Table_JuniorsD            1031
  371. #define ID_Output_Table_JuniorsE            1032
  372. #define ID_Output_TableProgress             1033
  373. #define ID_Output_DWZReport                 1034
  374. #define ID_Output_CrossTable                1035
  375. #define ID_Output_CrossTable_Ascii          1036
  376. #define ID_Output_CrossTable_TeX            1037
  377. #define ID_Output_PlayerCards               1038
  378. #define ID_Output_PlayerCards_Ascii         1039
  379. #define ID_Output_PlayerCards_TeX           1040
  380. #define ID_Prefs_Scoring                    1041
  381. #define ID_Prefs_Scoring_Simple             1042
  382. #define ID_Prefs_Scoring_Buchholz           1043
  383. #define ID_Prefs_Scoring_ExtBuchholz        1044
  384. #define ID_Prefs_Scoring_SonnebornBerger    1045
  385. #define ID_Prefs_Device                     1046
  386. #define ID_Prefs_Device_Screen              1047
  387. #define ID_Prefs_Device_PrinterDraft        1048
  388. #define ID_Prefs_Device_PrinterLQ           1049
  389. #define ID_Prefs_Device_File                1050
  390. #define ID_Prefs_SetGames                   1051
  391. #define ID_Prefs_MakeIcons                  1052
  392. #endif  /*  Amiga   */
  393.  
  394. void InitMainWnd(void)
  395.  
  396. #ifdef AMIGA
  397. { int open;
  398.   extern void MakeDisplay(void);
  399.   extern struct MUI_Command ARexxCommands[];
  400.  
  401.   static struct NewMenu MainNewMenu[] = {
  402.     NM_TITLE, (STRPTR) _MSG_TOURNAMENT_MENU,                NULL,                           0,                  NULL, NULL,
  403.     NM_ITEM,  (STRPTR) _MSG_TOURNAMENT_NEW_ITEM,            NULL,                           0,                  0L, (APTR)ID_Project_New,
  404.     NM_ITEM,  (STRPTR) _MSG_TOURNAMENT_LOAD_ITEM,           (STRPTR) _KEY_PROJECT_LOAD,     0,                  0L, (APTR)ID_Project_Load,
  405.     NM_ITEM,  (STRPTR) _MSG_TOURNAMENT_SAVE_ITEM,           (STRPTR) _KEY_PROJECT_SAVE,     0,                  0L, (APTR)ID_Project_Save,
  406.     NM_ITEM,  (STRPTR) _MSG_TOURNAMENT_SAVEAS_ITEM,         (STRPTR) _KEY_PROJECT_SAVE_AS,  0,                  0L, (APTR)ID_Project_SaveAs,
  407.     NM_ITEM,  (STRPTR) _MSG_TOURNAMENT_ABOUT_ITEM,          (STRPTR) _KEY_PROJECT_ABOUT,    0,                  0L, (APTR)ID_Project_About,
  408.     NM_ITEM,  (STRPTR) _MSG_TOURNAMENT_QUIT_ITEM,           NULL,                           0,                  0L, (APTR)ID_Project_Quit,
  409.     NM_TITLE, (STRPTR) _MSG_PLAYER_MENU,                    NULL,                           0,                  NULL, NULL,
  410.     NM_ITEM,  (STRPTR) _MSG_PLAYER_ADD_ITEM,                (STRPTR) _KEY_PLAYERS_NEW,      0,                  0L, (APTR)ID_Players_Add,
  411.     NM_ITEM,  (STRPTR) _MSG_PLAYER_IMPORT_ITEM,             NULL,                           0,                  0L, (APTR)ID_Players_Import,
  412.     NM_ITEM,  (STRPTR) _MSG_PLAYER_MODIFY_ITEM,             (STRPTR) _KEY_PLAYERS_MODIFY,   0,                  0L, (APTR)ID_Players_Modify,
  413.     NM_ITEM,  (STRPTR) _MSG_PLAYER_DELETE_ITEM,             NULL,                           0,                  0L, (APTR)ID_Players_Delete,
  414.     NM_TITLE, (STRPTR) _MSG_ROUND_MENU,                     NULL,                           0,                  NULL, NULL,
  415.     NM_ITEM,  (STRPTR) _MSG_ROUND_PAIRINGS_ITEM,            NULL,                           0,                  0L, (APTR)ID_Round_Pairings,
  416.     NM_SUB,   (STRPTR) _MSG_ROUND_PAIRINGS_SWISS_SUB,       NULL,                           0,                  0L, (APTR)ID_Round_Pairings_SwissPairing,
  417.     NM_SUB,   (STRPTR) _MSG_ROUND_PAIRINGS_RROBIN_SUB,      NULL,                           0,                  0L, (APTR)ID_Round_Pairings_RoundRobin,
  418.     NM_SUB,   (STRPTR) _MSG_ROUND_PAIRINGS_SLIDE_SUB,       NULL,                           0,                  0L, (APTR)ID_Round_Pairings_RoundRobinShift,
  419.     NM_ITEM,  (STRPTR) _MSG_ROUND_RESULTS_ITEM,             NULL,                           0,                  0L, (APTR)ID_Round_Results,
  420.     NM_TITLE, (STRPTR) _MSG_OUTPUT_MENU,                    NULL,                           0,                  NULL, NULL,
  421.     NM_ITEM,  (STRPTR) _MSG_OUTPUT_PLAYERS_ITEM,            NULL,                           0,                  0L, (APTR)ID_Output_PlayerList,
  422.     NM_SUB,   (STRPTR) _MSG_OUTPUT_PLAYERS_SHORT_SUB,       NULL,                           0,                  0L, (APTR)ID_Output_PlayerList_Short,
  423.     NM_SUB,   (STRPTR) _MSG_OUTPUT_PLAYERS_LONG_SUB,        NULL,                           0,                  0L, (APTR)ID_Output_PlayerList_Long,
  424.     NM_ITEM,  (STRPTR) _MSG_OUTPUT_RANKINGS_ITEM,           NULL,                           0,                  0L, (APTR)ID_Output_Rankings,
  425.     NM_ITEM,  (STRPTR) _MSG_OUTPUT_ROUND_ITEM,              NULL,                           0,                  0L, (APTR)ID_Output_Round,
  426.     NM_ITEM,  (STRPTR) _MSG_OUTPUT_TABLE_ITEM,              NULL,                           0,                  0L, (APTR)ID_Output_Table,
  427.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_ALL_SUB,           NULL,                           0,                  0L, (APTR)ID_Output_Table_All,
  428.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_SENIORS_SUB,       NULL,                           0,                  0L, (APTR)ID_Output_Table_Seniors,
  429.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_JUNIORS_SUB,       NULL,                           0,                  0L, (APTR)ID_Output_Table_Juniors,
  430.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_WOMEN_SUB    ,     NULL,                           0,                  0L, (APTR)ID_Output_Table_Women,
  431.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_JUNIORSA_SUB,      NULL,                           0,                  0L, (APTR)ID_Output_Table_JuniorsA,
  432.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_JUNIORSB_SUB,      NULL,                           0,                  0L, (APTR)ID_Output_Table_JuniorsB,
  433.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_JUNIORSC_SUB,      NULL,                           0,                  0L, (APTR)ID_Output_Table_JuniorsC,
  434.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_JUNIORSD_SUB,      NULL,                           0,                  0L, (APTR)ID_Output_Table_JuniorsD,
  435.     NM_SUB,   (STRPTR) _MSG_OUTPUT_TABLE_JUNIORSE_SUB,      NULL,                           0,                  0L, (APTR)ID_Output_Table_JuniorsE,
  436.     NM_ITEM,  (STRPTR) _MSG_OUTPUT_PROGRESSTABLE_ITEM,      NULL,                           0,                  0L, (APTR)ID_Output_TableProgress,
  437.     NM_ITEM,  (STRPTR) _MSG_OUTPUT_DWZ_ITEM,                NULL,                           0,                  0L, (APTR)ID_Output_DWZReport,
  438.     NM_ITEM,  (STRPTR) _MSG_OUTPUT_CROSSTABLE_ITEM,         NULL,                           0,                  0L, (APTR)ID_Output_CrossTable,
  439.     NM_SUB,   (STRPTR) _MSG_OUTPUT_CROSSTABLE_ASC_SUB,      NULL,                           0,                  0L, (APTR)ID_Output_CrossTable_Ascii,
  440.     NM_SUB,   (STRPTR) _MSG_OUTPUT_CROSSTABLE_TEX_SUB,      NULL,                           0,                  0L, (APTR)ID_Output_CrossTable_TeX,
  441.     NM_ITEM,  (STRPTR) _MSG_OUTPUT_PLAYERCARDS_ITEM,        NULL,                           0,                  0L, (APTR)ID_Output_PlayerCards,
  442.     NM_SUB,   (STRPTR) _MSG_OUTPUT_PLAYERCARDS_ASC_SUB,     NULL,                           0,                  0L, (APTR)ID_Output_PlayerCards_Ascii,
  443.     NM_SUB,   (STRPTR) _MSG_OUTPUT_PLAYERCARDS_TEX_SUB,     NULL,                           0,                  0L, (APTR)ID_Output_PlayerCards_TeX,
  444.     NM_TITLE, (STRPTR) _MSG_PREFS_MENU,                     NULL,                           0,                  NULL, NULL,
  445.     NM_ITEM,  (STRPTR) _MSG_PREFS_TMODE_ITEM,               NULL,                           0,                  0L, (APTR)ID_Prefs_Scoring,
  446.     NM_SUB,   (STRPTR) _MSG_PREFS_TMODE_SIMPLE_SUB,         NULL,                           CHECKIT|CHECKED,    14L, (APTR)ID_Prefs_Scoring_Simple,
  447.     NM_SUB,   (STRPTR) _MSG_PREFS_TMODE_BUCHHOLZ_SUB,       NULL,                           CHECKIT,            13L, (APTR)ID_Prefs_Scoring_Buchholz,
  448.     NM_SUB,   (STRPTR) _MSG_PREFS_TMODE_EXTBCHHLZ_SUB,      NULL,                           CHECKIT,            11L, (APTR)ID_Prefs_Scoring_ExtBuchholz,
  449.     NM_SUB,   (STRPTR) _MSG_PREFS_TMODE_SONNEBORN_SUB,      NULL,                           CHECKIT,            7L, (APTR)ID_Prefs_Scoring_SonnebornBerger,
  450.     NM_ITEM,  (STRPTR) _MSG_PREFS_OUT_ITEM,                 NULL,                           0,                  0L, (APTR)ID_Prefs_Device,
  451.     NM_SUB,   (STRPTR) _MSG_PREFS_OUT_SCREEN_SUB,           NULL,                           CHECKIT|CHECKED,    14L, (APTR)ID_Prefs_Device_Screen,
  452.     NM_SUB,   (STRPTR) _MSG_PREFS_OUT_PRTDRAFT_SUB,         NULL,                           CHECKIT,            13L, (APTR)ID_Prefs_Device_PrinterDraft,
  453.     NM_SUB,   (STRPTR) _MSG_PREFS_OUT_PRTLQ_SUB,            NULL,                           CHECKIT,            11L, (APTR)ID_Prefs_Device_PrinterLQ,
  454.     NM_SUB,   (STRPTR) _MSG_PREFS_OUT_FILE_SUB,             NULL,                           CHECKIT,            7L, (APTR)ID_Prefs_Device_File,
  455.     NM_ITEM,  (STRPTR) _MSG_PREFS_SETGAMES,                 NULL,                           CHECKIT|MENUTOGGLE, 0L, (APTR)ID_Prefs_SetGames,
  456.     NM_ITEM,  (STRPTR) _MSG_PREFS_MAKEICONS_ITEM,           NULL,                           CHECKIT|MENUTOGGLE, 0L, (APTR)ID_Prefs_MakeIcons,
  457.     NM_END,   NULL, NULL, 0, 0L, NULL,
  458.     /*
  459.         32 empty entries are following here. The 'special' menu will be
  460.         probably put in here.
  461.     */
  462.     NM_END,   NULL, NULL, 0, 0L, NULL,
  463.     NM_END,   NULL, NULL, 0, 0L, NULL,
  464.     NM_END,   NULL, NULL, 0, 0L, NULL,
  465.     NM_END,   NULL, NULL, 0, 0L, NULL,
  466.     NM_END,   NULL, NULL, 0, 0L, NULL,
  467.     NM_END,   NULL, NULL, 0, 0L, NULL,
  468.     NM_END,   NULL, NULL, 0, 0L, NULL,
  469.     NM_END,   NULL, NULL, 0, 0L, NULL,
  470.     NM_END,   NULL, NULL, 0, 0L, NULL,
  471.     NM_END,   NULL, NULL, 0, 0L, NULL,
  472.     NM_END,   NULL, NULL, 0, 0L, NULL,
  473.     NM_END,   NULL, NULL, 0, 0L, NULL,
  474.     NM_END,   NULL, NULL, 0, 0L, NULL,
  475.     NM_END,   NULL, NULL, 0, 0L, NULL,
  476.     NM_END,   NULL, NULL, 0, 0L, NULL,
  477.     NM_END,   NULL, NULL, 0, 0L, NULL,
  478.     NM_END,   NULL, NULL, 0, 0L, NULL,
  479.     NM_END,   NULL, NULL, 0, 0L, NULL,
  480.     NM_END,   NULL, NULL, 0, 0L, NULL,
  481.     NM_END,   NULL, NULL, 0, 0L, NULL,
  482.     NM_END,   NULL, NULL, 0, 0L, NULL,
  483.     NM_END,   NULL, NULL, 0, 0L, NULL,
  484.     NM_END,   NULL, NULL, 0, 0L, NULL,
  485.     NM_END,   NULL, NULL, 0, 0L, NULL,
  486.     NM_END,   NULL, NULL, 0, 0L, NULL,
  487.     NM_END,   NULL, NULL, 0, 0L, NULL,
  488.     NM_END,   NULL, NULL, 0, 0L, NULL,
  489.     NM_END,   NULL, NULL, 0, 0L, NULL,
  490.     NM_END,   NULL, NULL, 0, 0L, NULL,
  491.     NM_END,   NULL, NULL, 0, 0L, NULL,
  492.     NM_END,   NULL, NULL, 0, 0L, NULL,
  493.     NM_END,   NULL, NULL, 0, 0L, NULL
  494.   };
  495.  
  496.   /*
  497.       Localize the menu
  498.   */
  499.   { struct NewMenu *nm;
  500.  
  501.     for(nm = MainNewMenu;  nm->nm_Type != NM_END;  nm++)
  502.     { if (nm->nm_Label  &&  nm->nm_Label != NM_BARLABEL)
  503.       { nm->nm_Label = ((struct FC_String *) nm->nm_Label)->msg;
  504.       }
  505.       if (nm->nm_CommKey)
  506.       { nm->nm_CommKey = ((struct FC_String *) nm->nm_CommKey)->msg;
  507.       }
  508.     }
  509.   }
  510.  
  511.   /*
  512.       Reading the menu file.
  513.   */
  514.   { FILE *fh;
  515.  
  516.     if ((fh = fopen(MenuName, "r"))  !=  NULL  ||
  517.         (fh = fopen("s:Chaos_Menu", "r"))  !=  NULL)
  518.     { int size;
  519.       char *menufile;
  520.  
  521.       fseek(fh, 0, SEEK_END);
  522.       size = ftell(fh);
  523.       if ((menufile = malloc(size+1))  ==  NULL)
  524.       { ShowError("Cannot read menufile, ignoring.");
  525.       }
  526.       else
  527.       { fseek(fh, 0, SEEK_SET);
  528.         if (fread(menufile, size, 1, fh)  !=  1)
  529.         { ShowError("Cannot read menufile, ignoring.");
  530.         }
  531.         else
  532.         { int NumLines = 0;
  533.           struct NewMenu *nm = MainNewMenu;
  534.  
  535.           /*
  536.               Look, where to put in the special menu.
  537.           */
  538.           while (nm->nm_Type != NM_END)
  539.           { nm++;
  540.           }
  541.  
  542.           /*
  543.               Creating the menu header
  544.           */
  545.           nm->nm_Type = NM_TITLE;
  546.           nm->nm_Label = MSG_SPECIAL_MENU;
  547.  
  548.           /*
  549.               Scanning the menu file
  550.           */
  551.           menufile[size] = '\0';
  552.           while(*menufile != 0  &&  NumLines < 31)
  553.           { ++nm;
  554.             ++NumLines;
  555.             nm->nm_Type = NM_ITEM;
  556.             nm->nm_Label = (STRPTR) menufile;
  557.             while(*menufile != '\n'  &&  *menufile != '\0')
  558.             { ++menufile;
  559.             }
  560.             if (*menufile != '\0')
  561.             { *menufile = '\0';
  562.               nm->nm_UserData = (APTR) ++menufile;
  563.               while(*menufile != '\n'  &&  *menufile != '\0')
  564.               { ++menufile;
  565.               }
  566.               if (*menufile != '\0')
  567.               { *(menufile++) = '\0';
  568.               }
  569.             }
  570.           }
  571.         }
  572.       }
  573.       fclose(fh);
  574.     }
  575.   }
  576.  
  577.   /*
  578.       Get the programs icon to show it in iconified state.
  579.   */
  580.   AppDiskObject = GetDiskObject((STRPTR) ProgName);
  581.  
  582.   /*
  583.       Creating the GUI
  584.   */
  585.   App = ApplicationObject,
  586.             MUIA_Application_Title,         "Chaos",
  587.             MUIA_Application_Version,       VERVERSION,
  588.             MUIA_Application_Copyright,     "© 1993, Jochen Wiedmann",
  589.             MUIA_Application_Author,        "Jochen Wiedmann",
  590.             MUIA_Application_Description,   "The Chess HAppening Organisation System",
  591.             MUIA_Application_Base,          "CHAOS",
  592.             MUIA_Application_Commands,      ARexxCommands,
  593.             AppDiskObject ? MUIA_Application_DiskObject : TAG_IGNORE,
  594.                                             AppDiskObject,
  595.             SubWindow, MainWnd = WindowObject,
  596.                 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  597.                 MUIA_Window_Title, AVERSION,
  598.                 MUIA_Window_Menustrip, MainMenu = MUI_MakeObject(MUIO_MenustripNM, MainNewMenu, 0),
  599.                 WindowContents, VGroup,
  600.                     Child, TextObject,
  601.                         GroupFrame,
  602.                         MUIA_Background, MUII_FILLBACK2,
  603.                         MUIA_Text_Contents, "\033cC h a o s\n"
  604.                                             "\033cThe Chess HAppening Organisation System\n"
  605.                                             "Copyright © 1993,      Jochen Wiedmann",
  606.                     End,
  607.                     Child, ColGroup(2),
  608.                         Child, Label2(MSG_TOURNAMENT_FILE_OUTPUT),
  609.                         Child, TrnFileGad = TextObject,
  610.                         End,
  611.                         Child, Label2(MSG_TOURNAMENT_NAME_OUTPUT),
  612.                         Child, TrnNameGadOut = TextObject,
  613.                         End,
  614.                         Child, Label2(MSG_TOURNAMENT_MODE_OUTPUT),
  615.                         Child, TrnModeGad = TextObject,
  616.                         End,
  617.                     End,
  618.                     Child, HGroup,
  619.                         Child, Label2(MSG_NUM_PLAYERS_OUTPUT),
  620.                         Child, NumPlayersGad = TextObject,
  621.                         End,
  622.                         Child, HSpace(0),
  623.                         Child, Label2(MSG_NUM_ROUNDS_OUTPUT),
  624.                         Child, NumRoundsGad = TextObject,
  625.                         Child, HSpace(0),
  626.                         End,
  627.                     End,
  628.                 End,
  629.             End,
  630.         End;
  631.  
  632.   /*
  633.       Successfull?
  634.   */
  635.   if (App == NULL)
  636.   { ShowError(MSG_MEMORY_ERROR);
  637.     exit(10);
  638.   }
  639.  
  640.   /*
  641.       Setting up the notification events for the main window
  642.   */
  643.   DoMethod(MainWnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, App, 2,
  644.            MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  645.   DoMethod(App, MUIM_Notify, MUIA_Application_MenuAction, MUIV_EveryTime,
  646.            App, 2, MUIM_Application_ReturnID, ID_MenuAction);
  647.  
  648.  
  649.  
  650.   /*
  651.       Opening the main window and checking for success
  652.   */
  653.   if (!NoWindow)
  654.   { set (MainWnd, MUIA_Window_Open, TRUE);
  655.     MakeDisplay();
  656.     get (MainWnd, MUIA_Window_Open, &open);
  657.     if (!open)
  658.     { MUIError((char *) ERRMSG_CANNOT_OPEN_WINDOW);
  659.       TerminateMainWnd();
  660.     }
  661.   }
  662. }
  663. #endif  /*  AMIGA   */
  664.  
  665.  
  666.  
  667.  
  668. /*
  669.     The ShowError() function should bring up a requester telling an error.
  670. */
  671. void ShowError(char *msg, ...)
  672.  
  673. #ifdef AMIGA
  674. {
  675.   if (App)
  676.   { MUI_RequestA(App, MainWnd, 0, (char *) MSG_ERROR_REQUEST,
  677.                (char *) MSG_OK, msg, (&msg)+1);
  678.   }
  679.   else if (IntuitionBase)
  680.   { struct EasyStruct es;
  681.  
  682.     es.es_StructSize = sizeof(es);
  683.     es.es_Flags = 0;
  684.     es.es_Title = MSG_ERROR_REQUEST;
  685.     es.es_TextFormat = (STRPTR) msg;
  686.     es.es_GadgetFormat = MSG_OK;
  687.     EasyRequestArgs(NULL, &es, NULL, (&msg)+1);
  688.   }
  689.   else if (AllowErrorMessage)
  690.   { printf("%s\n", msg);
  691.   }
  692. }
  693. #endif  /*  AMIGA   */
  694.  
  695.  
  696.  
  697. #ifdef AMIGA
  698. /*
  699.     The following function gets called, if an MUI command fails.
  700.  
  701. */
  702. void MUIError(char *msg)
  703. { char *errmsg;
  704.  
  705.   switch (MUI_Error())
  706.   { case MUIE_OK:
  707.       errmsg = (char *) MUIERR_OK;
  708.       break;
  709.     case MUIE_OutOfMemory:
  710.       errmsg = (char *) MUIERR_OutOfMemory;
  711.       break;
  712.     case MUIE_OutOfGfxMemory:
  713.       errmsg = (char *) MUIERR_OutOfGfxMemory;
  714.       break;
  715.     case MUIE_InvalidWindowObject:
  716.       errmsg = (char *) MUIERR_InvalidWindowObject;
  717.       break;
  718.     case MUIE_MissingLibrary:
  719.       errmsg = (char *) MUIERR_MissingLibrary;
  720.       break;
  721.     case MUIE_NoARexx:
  722.       errmsg = (char *) MUIERR_NoARexx;
  723.       break;
  724.     case MUIE_SingleTask:
  725.       errmsg = (char *) MUIERR_SingleTask;
  726.       break;
  727.     default:
  728.       errmsg = (char *) MUIERR_Unknown;
  729.   }
  730.  
  731.   ShowError(msg, errmsg);
  732. }
  733. #endif  /*  AMIGA   */
  734.  
  735.  
  736.  
  737.  
  738. /*
  739.     MemError() gets called, when memory is missing.
  740. */
  741. void MemError(void)
  742.  
  743. { ShowError((char *) MSG_MEMORY_ERROR);
  744. }
  745.  
  746.  
  747.  
  748.  
  749. /*
  750.     MakeDisplay() refreshs the information gadgets, enables or disables the
  751.     menuitems and looks for the menu preferences.
  752. */
  753. void MakeDisplay(void)
  754.  
  755. #ifdef AMIGA
  756. { char numrounds[10], numplayers[10];
  757.   Object *menuObj;
  758.  
  759.   /*
  760.       Information gadgets
  761.   */
  762.   set(TrnFileGad, MUIA_Text_Contents, TrnFileName);
  763.   set (TrnNameGadOut, MUIA_Text_Contents, TrnName);
  764.   switch (TrnMode &
  765.           (TNMODEF_SWISS_PAIRING|TNMODEF_ROUND_ROBIN|TNMODEF_SHIFT_SYSTEM))
  766.   { case 0:
  767.       set(TrnModeGad, MUIA_Text_Contents, NULL);
  768.       break;
  769.     case TNMODEF_SWISS_PAIRING:
  770.       set(TrnModeGad, MUIA_Text_Contents, MSG_SWISS_PAIRING);
  771.       break;
  772.     case TNMODEF_ROUND_ROBIN:
  773.       set(TrnModeGad, MUIA_Text_Contents, MSG_RUNDENTURNIER);
  774.       break;
  775.     default:
  776.       set(TrnModeGad, MUIA_Text_Contents, MSG_RUTSCHSYSTEM);
  777.       break;
  778.   }
  779.   sprintf(numrounds, "%d", NumRounds);
  780.   set(NumRoundsGad, MUIA_Text_Contents, numrounds);
  781.   sprintf(numplayers, "%d", NumPlayers);
  782.   set(NumPlayersGad, MUIA_Text_Contents, numplayers);
  783.  
  784.  
  785.   /*
  786.       Enabling and disabling menu items
  787.   */
  788. #define SetMenu(id, flag)                                                   \
  789.     if ((menuObj = (Object *) DoMethod(MainMenu, MUIM_FindUData, (id))))    \
  790.     { set(menuObj, MUIA_Menuitem_Enabled, (flag));                          \
  791.     }
  792.  
  793.   SetMenu(ID_Players_Add,
  794.           !((RoundRobinTournament  &&  NumRounds > 0)  ||
  795.             (SwissPairingTournament  &&  NumRounds > 1)));
  796.   SetMenu(ID_Players_Import,
  797.           !((RoundRobinTournament  &&  NumRounds > 0)  ||
  798.             (SwissPairingTournament  &&  NumRounds > 1)));
  799.   SetMenu(ID_Players_Modify, NumPlayers > 0);
  800.   SetMenu(ID_Players_Delete,
  801.           (NumRounds == 0  &&  NumPlayers > 0)  || SwissPairingTournament);
  802.  
  803.   SetMenu(ID_Round_Pairings,
  804.           (NumRounds == 0  &&  NumPlayers > 0)  || SwissPairingTournament);
  805.   SetMenu(ID_Round_Pairings_SwissPairing,
  806.           (NumRounds == 0  &&  NumPlayers > 0)  ||
  807.           (SwissPairingTournament  &&  NumGamesMissing == 0));
  808.   SetMenu(ID_Round_Pairings_RoundRobin, NumRounds == 0  &&  NumPlayers > 0);
  809.   SetMenu(ID_Round_Pairings_RoundRobinShift,
  810.           NumRounds == 0  &&  NumPlayers > 0);
  811.   SetMenu(ID_Round_Results, NumRounds > 0);
  812.  
  813.   SetMenu(ID_Output_PlayerList, NumPlayers > 0);
  814.   SetMenu(ID_Output_Rankings, NumPlayers > 0);
  815.   SetMenu(ID_Output_Round, NumRounds > 0);
  816.   SetMenu(ID_Output_Table, NumRounds > 0);
  817.   SetMenu(ID_Output_TableProgress, SwissPairingTournament);
  818.   SetMenu(ID_Output_CrossTable, RoundRobinTournament);
  819.   SetMenu(ID_Output_PlayerCards,
  820.           (NumPlayers > 0  &&  NumRounds == 0)  ||  SwissPairingTournament);
  821.   SetMenu(ID_Output_DWZReport, NumRounds > 0);
  822.  
  823.   SetMenu(ID_Prefs_Scoring, NumRounds > 0);
  824.   SetMenu(ID_Prefs_Scoring_Buchholz, SwissPairingTournament);
  825.   SetMenu(ID_Prefs_Scoring_ExtBuchholz, SwissPairingTournament);
  826.   SetMenu(ID_Prefs_Scoring_SonnebornBerger, RoundRobinTournament);
  827.  
  828.   /*
  829.       Finally let the items of the preferences menu reflect the current
  830.       settings
  831.   */
  832. #define SetMenuCheck(id, flag)                                              \
  833.     if ((menuObj = (Object *) DoMethod(MainMenu, MUIM_FindUData, (id))))    \
  834.     { set(menuObj, MUIA_Menuitem_Checked, (flag));                          \
  835.     } 
  836.  
  837.   switch(TrnMode & TNMODE_TABMASK)
  838.   { case 0:
  839.       SetMenuCheck(ID_Prefs_Scoring_Simple, TRUE);
  840.       SetMenuCheck(ID_Prefs_Scoring_Buchholz, FALSE);
  841.       SetMenuCheck(ID_Prefs_Scoring_ExtBuchholz, FALSE);
  842.       SetMenuCheck(ID_Prefs_Scoring_SonnebornBerger, FALSE);
  843.       break;
  844.     case TNMODEF_BUCHHOLZ:
  845.       SetMenuCheck(ID_Prefs_Scoring_Simple, FALSE);
  846.       SetMenuCheck(ID_Prefs_Scoring_Buchholz, TRUE);
  847.       SetMenuCheck(ID_Prefs_Scoring_ExtBuchholz, FALSE);
  848.       SetMenuCheck(ID_Prefs_Scoring_SonnebornBerger, FALSE);
  849.       break;
  850.     case TNMODEF_EXT_BUCHHOLZ:
  851.       SetMenuCheck(ID_Prefs_Scoring_Simple, FALSE);
  852.       SetMenuCheck(ID_Prefs_Scoring_Buchholz, FALSE);
  853.       SetMenuCheck(ID_Prefs_Scoring_ExtBuchholz, TRUE);
  854.       SetMenuCheck(ID_Prefs_Scoring_SonnebornBerger, FALSE);
  855.       break;
  856.     case TNMODEF_SONNEBORN_BERGER:
  857.       SetMenuCheck(ID_Prefs_Scoring_Simple, FALSE);
  858.       SetMenuCheck(ID_Prefs_Scoring_Buchholz, FALSE);
  859.       SetMenuCheck(ID_Prefs_Scoring_ExtBuchholz, FALSE);
  860.       SetMenuCheck(ID_Prefs_Scoring_SonnebornBerger, TRUE);
  861.       break;
  862.   }
  863.   switch (OutputDevice)
  864.   { case DEVICE_Screen:
  865.       SetMenuCheck(ID_Prefs_Device_Screen, TRUE);
  866.       SetMenuCheck(ID_Prefs_Device_PrinterDraft, FALSE);
  867.       SetMenuCheck(ID_Prefs_Device_PrinterLQ, FALSE);
  868.       SetMenuCheck(ID_Prefs_Device_File, FALSE);
  869.       break;
  870.     case DEVICE_PrinterDraft:
  871.       SetMenuCheck(ID_Prefs_Device_Screen, FALSE);
  872.       SetMenuCheck(ID_Prefs_Device_PrinterDraft, TRUE);
  873.       SetMenuCheck(ID_Prefs_Device_PrinterLQ, FALSE);
  874.       SetMenuCheck(ID_Prefs_Device_File, FALSE);
  875.       break;
  876.     case DEVICE_PrinterLQ:
  877.       SetMenuCheck(ID_Prefs_Device_Screen, FALSE);
  878.       SetMenuCheck(ID_Prefs_Device_PrinterDraft, FALSE);
  879.       SetMenuCheck(ID_Prefs_Device_PrinterLQ, TRUE);
  880.       SetMenuCheck(ID_Prefs_Device_File, FALSE);
  881.       break;
  882.     case DEVICE_FileAscii:
  883.       SetMenuCheck(ID_Prefs_Device_Screen, FALSE);
  884.       SetMenuCheck(ID_Prefs_Device_PrinterDraft, FALSE);
  885.       SetMenuCheck(ID_Prefs_Device_PrinterLQ, FALSE);
  886.       SetMenuCheck(ID_Prefs_Device_File, TRUE);
  887.       break;
  888.   }
  889.   SetMenuCheck(ID_Prefs_MakeIcons, MakeIcons);
  890. }
  891. #endif  /*  AMIGA   */
  892.  
  893.  
  894.  
  895.  
  896. /*
  897.     ProcessMainWnd() waits for user actions like selecting a menu or
  898.     messages from the ARexx-port and processes them in an endless loop.
  899. */
  900. int EnableARexx = TRUE;
  901. static int GamesToBeSet = FALSE;
  902. void ProcessMainWnd(void)
  903.  
  904. #ifdef AMIGA
  905. { ULONG Signal, open, ID;
  906.   APTR UserData;
  907.   int round, initMenu;
  908.  
  909.   for (;;)
  910.   { /*
  911.         Disable the menus, so the window is sleeping for our purposes.
  912.     */
  913.     set (MainWnd, MUIA_Window_NoMenus, TRUE);
  914.  
  915.     /*
  916.         Check for user actions
  917.     */
  918.     ID = DoMethod(App, MUIM_Application_Input, &Signal);
  919.     EnableARexx = FALSE;
  920.     initMenu = FALSE;
  921.     switch(ID)
  922.     { case MUIV_Application_ReturnID_Quit:
  923.         if (TestSaved())
  924.         { exit(0);
  925.         }
  926.         break;
  927.       case ID_MenuAction:
  928.         get(App, MUIA_Application_MenuAction, &UserData);
  929.         switch((ULONG) UserData)
  930.         { case ID_Project_Quit:
  931.             if (TestSaved())
  932.             { exit(0);
  933.             }
  934.             break;
  935.           case ID_Project_New:
  936.             if (TestSaved())
  937.             { NewTournament();
  938.               initMenu = TRUE;
  939.             }
  940.             break;
  941.           case ID_Project_Load:
  942.             if (TestSaved())
  943.             { LoadTournament(NULL, NULL, NULL);
  944.               initMenu = TRUE;
  945.             }
  946.             break;
  947.           case ID_Project_Save:
  948.             SaveTournament(TrnFileName);
  949.             break;
  950.           case ID_Project_SaveAs:
  951.             SaveTournament(NULL);
  952.             initMenu = TRUE;
  953.             break;
  954.           case ID_Project_About:
  955.             About();
  956.             break;
  957.           case ID_Players_Add:
  958.             AddPlayers();
  959.             initMenu = TRUE;
  960.             break;
  961.           case ID_Players_Import:
  962.             ImportPlayers();
  963.             initMenu = TRUE;
  964.             break;
  965.           case ID_Players_Modify:
  966.             ModifyPlayers();
  967.             initMenu = TRUE;
  968.             break;
  969.           case ID_Players_Delete:
  970.             DeletePlayers();
  971.             initMenu = TRUE;
  972.             break;
  973.           case ID_Round_Pairings_SwissPairing:
  974.             DoPairings(TNMODEF_SWISS_PAIRING, TRUE, GamesToBeSet);
  975.             initMenu = TRUE;
  976.             break;
  977.           case ID_Round_Pairings_RoundRobin:
  978.             DoPairings(TNMODEF_ROUND_ROBIN, TRUE, FALSE);
  979.             initMenu = TRUE;
  980.             break;
  981.           case ID_Round_Pairings_RoundRobinShift:
  982.             DoPairings(TNMODEF_ROUND_ROBIN | TNMODEF_SHIFT_SYSTEM, TRUE, FALSE);
  983.             initMenu = TRUE;
  984.             break;
  985.           case ID_Round_Results:
  986.             if ((round = GetRoundNr()) != 0)
  987.             { EnterResults(round);
  988.               initMenu = TRUE;
  989.             }
  990.             break;
  991.           case ID_Output_PlayerList_Short:
  992.             OutPlayerList(NULL, OutputDevice, FALSE);
  993.             break;
  994.           case ID_Output_PlayerList_Long:
  995.             OutPlayerList(NULL, OutputDevice, TRUE);
  996.             break;
  997.           case ID_Output_Rankings:
  998.             OutInternalRankings(NULL, OutputDevice);
  999.             break;
  1000.           case ID_Output_Round:
  1001.             if ((round = GetRoundNr()) != 0)
  1002.             { OutRound(NULL, OutputDevice, round);
  1003.             }
  1004.             break;
  1005.           case ID_Output_Table_All:
  1006.             OutTable(NULL, OutputDevice, 0, TrnMode);
  1007.             break;
  1008.           case ID_Output_Table_Seniors:
  1009.             OutTable(NULL, OutputDevice, TNFLAGSF_SENIOR, TrnMode);
  1010.             break;
  1011.           case ID_Output_Table_Juniors:
  1012.             OutTable(NULL, OutputDevice, TNFLAGSF_JUNIOR, TrnMode);
  1013.             break;
  1014.           case ID_Output_Table_Women:
  1015.             OutTable(NULL, OutputDevice, TNFLAGSF_WOMAN, TrnMode);
  1016.             break;
  1017.           case ID_Output_Table_JuniorsA:
  1018.             OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORA, TrnMode);
  1019.             break;
  1020.           case ID_Output_Table_JuniorsB:
  1021.             OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORB, TrnMode);
  1022.             break;
  1023.           case ID_Output_Table_JuniorsC:
  1024.             OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORC, TrnMode);
  1025.             break;
  1026.           case ID_Output_Table_JuniorsD:
  1027.             OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORD, TrnMode);
  1028.             break;
  1029.           case ID_Output_Table_JuniorsE:
  1030.             OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORE, TrnMode);
  1031.             break;
  1032.           case ID_Output_TableProgress:
  1033.             OutTableProgress(NULL, OutputDevice, TrnMode);
  1034.             break;
  1035.           case ID_Output_DWZReport:
  1036.             OutDWZReport(NULL, OutputDevice);
  1037.             break;
  1038.           case ID_Output_CrossTable_Ascii:
  1039.             OutCrossTable(NULL, OutputDevice);
  1040.             break;
  1041.           case ID_Output_CrossTable_TeX:
  1042.             OutCrossTable(NULL, DEVICE_FileTeX);
  1043.             break;
  1044.           case ID_Output_PlayerCards_Ascii:
  1045.             OutPlayerCards(NULL, OutputDevice);
  1046.             break;
  1047.           case ID_Output_PlayerCards_TeX:
  1048.             OutPlayerCards(NULL, DEVICE_FileTeX);
  1049.             break;
  1050.           case ID_Prefs_Scoring_Simple:
  1051.             TrnMode &= ~TNMODE_TABMASK;
  1052.             initMenu = TRUE;
  1053.             break;
  1054.           case ID_Prefs_Scoring_Buchholz:
  1055.             TrnMode = (TrnMode & ~TNMODE_TABMASK) | TNMODEF_BUCHHOLZ;
  1056.             initMenu = TRUE;
  1057.             break;
  1058.           case ID_Prefs_Scoring_ExtBuchholz:
  1059.             TrnMode = (TrnMode & ~TNMODE_TABMASK) | TNMODEF_EXT_BUCHHOLZ;
  1060.             initMenu = TRUE;
  1061.             break;
  1062.           case ID_Prefs_Scoring_SonnebornBerger:
  1063.             TrnMode = (TrnMode & ~TNMODE_TABMASK) | TNMODEF_SONNEBORN_BERGER;
  1064.             initMenu = TRUE;
  1065.             break;
  1066.           case ID_Prefs_Device_Screen:
  1067.             OutputDevice = DEVICE_Screen;
  1068.             initMenu = TRUE;
  1069.             break;
  1070.           case ID_Prefs_Device_PrinterDraft:
  1071.             OutputDevice = DEVICE_PrinterDraft;
  1072.             initMenu = TRUE;
  1073.             break;
  1074.           case ID_Prefs_Device_PrinterLQ:
  1075.             OutputDevice = DEVICE_PrinterLQ;
  1076.             initMenu = TRUE;
  1077.             break;
  1078.           case ID_Prefs_Device_File:
  1079.             OutputDevice = DEVICE_FileAscii;
  1080.             initMenu = TRUE;
  1081.             break;
  1082.           case ID_Prefs_SetGames:
  1083.             GamesToBeSet = !GamesToBeSet;
  1084.             initMenu = TRUE;
  1085.             break;
  1086.           case ID_Prefs_MakeIcons:
  1087.             MakeIcons = !MakeIcons;
  1088.             initMenu = TRUE;
  1089.             break;
  1090.           default:
  1091.             if (UserData != NULL)
  1092.             { EnableARexx = TRUE;
  1093.               SystemTags(UserData, SYS_UserShell, NULL, TAG_END);
  1094.             }
  1095.             initMenu = TRUE;
  1096.         }
  1097.     }
  1098.     EnableARexx = TRUE;
  1099.  
  1100.     /*
  1101.         Let the window awake.
  1102.     */
  1103.     get(MainWnd, MUIA_Window_Open, &open);
  1104.     if (!NoWindow)
  1105.     { if (!open)
  1106.       { set(MainWnd, MUIA_Window_Open, TRUE);
  1107.       }
  1108.       if (initMenu)
  1109.       { MakeDisplay();
  1110.       }
  1111.       set(MainWnd, MUIA_Window_NoMenus, FALSE);
  1112.     }
  1113.     EnableARexx = TRUE;
  1114.  
  1115.  
  1116.     /*
  1117.         And put the application to sleep, waiting for user actions.
  1118.     */
  1119.     if(Signal)
  1120.     { Wait(Signal);
  1121.     }
  1122.   }
  1123. }
  1124. #endif  /*  AMIGA   */
  1125.  
  1126.  
  1127.  
  1128.  
  1129. /*
  1130.     SetupPrefs() sets up the preferences in a way corresponding to a new
  1131.     or loaded tournament.
  1132. */
  1133. void SetupPrefs(void)
  1134. #ifdef AMIGA
  1135. { switch (TrnMode &= TNMODE_TABMASK)
  1136.   { case TNMODEF_BUCHHOLZ:
  1137.       DoMethod(MainWnd, MUIM_Window_SetMenuCheck, ID_Prefs_Scoring_Buchholz,
  1138.                TRUE);
  1139.       break;
  1140.     case TNMODEF_EXT_BUCHHOLZ:
  1141.       DoMethod(MainWnd, MUIM_Window_SetMenuCheck,
  1142.                ID_Prefs_Scoring_ExtBuchholz, TRUE);
  1143.       break;
  1144.     case TNMODEF_SONNEBORN_BERGER:
  1145.       DoMethod(MainWnd, MUIM_Window_SetMenuCheck,
  1146.                ID_Prefs_Scoring_SonnebornBerger, TRUE);
  1147.       break;
  1148.     default:
  1149.       DoMethod(MainWnd, MUIM_Window_SetMenuCheck, ID_Prefs_Scoring_Simple,
  1150.                TRUE);
  1151.       break;
  1152.   }
  1153. }
  1154. #endif  /*  AMIGA   */
  1155.